﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using Library;

namespace BusinessLayer
{
   public class Order
    {

        private int order_ID;

        public int Order_ID
        {
            get { return order_ID; }
            set { order_ID = value; }
        }


        private DateTime order_Date;

        public DateTime Order_Date
        {
            get { return order_Date; }
            set { order_Date = value; }
        }


        private int member_ID;

        public int Member_ID
        {
            get { return member_ID; }
            set { member_ID = value; }
        }


        private int status;

        public int Status
        {
            get { return status; }
            set { status = value; }
        }

       
        #region "Initial Methods"
        public Order() { }
        public Order(SqlDataReader sdr)
        {
            if (sdr != null & !sdr.IsClosed)
            {
                Order_ID = sdr.GetInt32(0);
                if (sdr.IsDBNull(1))
                    order_Date = sdr.GetDateTime(1);
                if (sdr.IsDBNull(2))
                    member_ID = sdr.GetInt32(2);
                if (sdr.IsDBNull(3))
                    Status = sdr.GetInt32(3);

            }
        }
        #endregion
        #region "Business Methods"
        //Get all Order
        public static List<Order> GetAll()
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Order__SHOWALL";
            List<Order> lstOrder_Detail = new List<Order>();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            while (sdr.Read())
            {
                lstOrder_Detail.Add(new Order(sdr));
            }
            return lstOrder_Detail;
        } //Get one Order
        public static Order GetOne(int id)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Order_ID", id);
            string cmd = "tbl_Order_SHOWONE";
            Order order_detail = new Order();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            if (sdr.Read())
            {
                order_detail.Order_ID = sdr.GetInt32(0);
                if (!sdr.IsDBNull(1))
                    order_detail.Order_Date = sdr.GetDateTime(1);
                if (!sdr.IsDBNull(2))
                    order_detail.member_ID = sdr.GetInt32(2);
                if (!sdr.IsDBNull(3))
                    order_detail.Status = sdr.GetInt32(3);

            }
            return order_detail;
        }

        //Insert a Order
        public static void Insert(Order order_detail)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Quality", order_detail.member_ID);
            string cmd = "tbl_Order_INSERT";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

        //Update a Order
        public static void Update(Order order_detail)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Order_Id", order_detail.Order_ID);
            dbh.AddParameter("@Product_Id", order_detail.Order_Date);
            dbh.AddParameter("@Quality", order_detail.member_ID);
            string cmd = "tbl_Order_UPDATE";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

        //Delete a Order_Detail
        public static void Delete(int Id)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Order_ID", Id);
            string cmd = "tbl_Order_DELETE";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
        #endregion

    }
}
